package com.seuic.hnapps.project;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.orhanobut.logger.Logger;
import com.seuic.hnapps.BaseActivity;
import com.seuic.hnapps.R;
import com.seuic.hnapps.SquareLayout;
import com.seuic.hnapps.adapter.Transaction_Detail_Adapter;
import com.seuic.hnapps.bean.Pass_word_bean;
import com.seuic.hnapps.bean.StatisticalData_bean;
import com.seuic.hnapps.bean.Summary_Bean;
import com.seuic.hnapps.posdsdk.pos_func.PosCallbacks;
import com.seuic.hnapps.posdsdk.pos_func.PosFuncs;
import com.seuic.hnapps.util.Constants;
import com.seuic.hnapps.util.DateUtil;
import com.seuic.hnapps.util.Pass_word_Callback;
import com.seuic.hnapps.util.SFTPUtils;
import com.seuic.hnapps.util.SpUtils;
import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.io.FileInputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * isjingkai
 * 2019年7月20日10:54:47
 * 操作员业务
 */
public class OperatorServiceActivity extends BaseActivity {
    Runnable runnable;
    Handler handler;
    @BindView(R.id.sure_printingpeper_okbtn)
    Button surePrintingpeperOkbtn;
    @BindView(R.id.sure_printingpeper_layout)
    LinearLayout surePrintingpeperLayout;
    @BindView(R.id.znqk_money)
    TextView znqkMoney;
    @BindView(R.id.znqk_num)
    TextView znqkNum;
    @BindView(R.id.xjhk_money)
    TextView xjhkMoney;
    @BindView(R.id.xjhk_num)
    TextView xjhkNum;
    @BindView(R.id.zzhk_money)
    TextView zzhkMoney;
    @BindView(R.id.zzhk_num)
    TextView zzhkNum;
    @BindView(R.id.ydhf_money)
    TextView ydhfMoney;
    @BindView(R.id.ydhf_num)
    TextView ydhfNum;
    @BindView(R.id.lthf_money)
    TextView lthfMoney;
    @BindView(R.id.lthf_num)
    TextView lthfNum;
    @BindView(R.id.sgcz_money)
    TextView sgczMoney;
    @BindView(R.id.sgcz_num)
    TextView sgczNum;
    @BindView(R.id.dzh_money)
    TextView dzhMoney;
    @BindView(R.id.dzh_num)
    TextView dzhNum;
    @BindView(R.id.hzd_money)
    TextView hzdMoney;
    @BindView(R.id.hzd_num)
    TextView hzdNum;
    @BindView(R.id.zhgm_money)
    TextView zhgmMoney;
    @BindView(R.id.zhgm_num)
    TextView zhgmNum;
    @BindView(R.id.lwhc_money)
    TextView lwhcMoney;
    @BindView(R.id.lwhc_num)
    TextView lwhcNum;
    @BindView(R.id.ktgs_money)
    TextView ktgsMoney;
    @BindView(R.id.ktgs_num)
    TextView ktgsNum;
    @BindView(R.id.bdz_money)
    TextView bdzMoney;
    @BindView(R.id.bdz_num)
    TextView bdzNum;
    @BindView(R.id.jyhbdz_money)
    TextView jyhbdzMoney;
    @BindView(R.id.jyhbdz_num)
    TextView jyhbdzNum;
    @BindView(R.id.zhcqy_money)
    TextView zhcqyMoney;
    @BindView(R.id.zhcqy_num)
    TextView zhcqyNum;
    @BindView(R.id.zhcjy_money)
    TextView zhcjyMoney;
    @BindView(R.id.zhcjy_num)
    TextView zhcjyNum;
    @BindView(R.id.hnyqy_money)
    TextView hnyqyMoney;
    @BindView(R.id.hnyqy_num)
    TextView hnyqyNum;
    @BindView(R.id.hnyjy_money)
    TextView hnyjyMoney;
    @BindView(R.id.hnyjy_num)
    TextView hnyjyNum;
    @BindView(R.id.all_money)
    TextView allMoney;
    @BindView(R.id.all_num)
    TextView allNum;
    @BindView(R.id.change_password_title)
    TextView changePasswordTitle;
    @BindView(R.id.change_password_edtext)
    EditText changePasswordEdtext;
    @BindView(R.id.change_password_nobtn)
    Button changePasswordNobtn;
    @BindView(R.id.change_password_okbtn)
    Button changePasswordOkbtn;
    @BindView(R.id.change_password_layout)
    LinearLayout changePasswordLayout;
    @BindView(R.id.collect_info_nobtn)
    Button collectInfoNobtn;
    @BindView(R.id.changenew_password_edtext)
    EditText changenewPasswordEdtext;
    @BindView(R.id.changenew_password_nobtn)
    Button changenewPasswordNobtn;
    @BindView(R.id.changenew_password_okbtn)
    Button changenewPasswordOkbtn;
    @BindView(R.id.changenew_password_layout)
    LinearLayout changenewPasswordLayout;
    @BindView(R.id.changenew_password2_edtext)
    EditText changenewPassword2Edtext;
    @BindView(R.id.changenew_password2_nobtn)
    Button changenewPassword2Nobtn;
    @BindView(R.id.changenew_password2_okbtn)
    Button changenewPassword2Okbtn;
    @BindView(R.id.changenew_password2_layout)
    LinearLayout changenewPassword2Layout;
    @BindView(R.id.pirnt_btn)
    LinearLayout pirntBtn;
    private PosFuncs posFuncs;

    @BindView(R.id.base_back_btn)
    LinearLayout baseBackBtn;
    @BindView(R.id.base_title_text)
    TextView baseTitleText;
    @BindView(R.id.operator_service_uprunwater)
    SquareLayout operatorServiceUprunwater;
    @BindView(R.id.operator_service_changepassword)
    SquareLayout operatorServiceChangepassword;
    @BindView(R.id.operator_service_examine_statis)
    SquareLayout operatorServiceExamineStatis;
    @BindView(R.id.operator_service_examine_quit)
    SquareLayout operatorServiceExamineQuit;
    @BindView(R.id.operator_service_card_layout)
    CardView operatorServiceCardLayout;
    @BindView(R.id.operator_service_home_layout)
    LinearLayout operatorServiceHomeLayout;
    @BindView(R.id.dealing_layout)
    LinearLayout dealingLayout;
    @BindView(R.id.modification_success_text)
    TextView modificationSuccessText;
    @BindView(R.id.modification_success_okbtn)
    Button modificationSuccessOkbtn;
    @BindView(R.id.modification_success_layout)
    LinearLayout modificationSuccessLayout;
    @BindView(R.id.statistics_tosee_normal)
    Button statisticsToseeNormal;
    @BindView(R.id.statistics_tosee_collectl)
    Button statisticsToseeCollectl;
    @BindView(R.id.statistics_tosee_abnormal)
    Button statisticsToseeAbnormal;
    @BindView(R.id.statistics_tosee_layout)
    LinearLayout statisticsToseeLayout;
    @BindView(R.id.input_querytime_edtext)
    EditText inputQuerytimeEdtext;
    @BindView(R.id.input_querytime_nobtn)
    Button inputQuerytimeNobtn;
    @BindView(R.id.input_querytime_okbtn)
    Button inputQuerytimeOkbtn;
    @BindView(R.id.input_querytime_layout)
    LinearLayout inputQuerytimeLayout;
    @BindView(R.id.sign_out_nobtn)
    Button signOutNobtn;
    @BindView(R.id.sign_out_okbtn)
    Button signOutOkbtn;
    @BindView(R.id.sign_out_layout)
    LinearLayout signOutLayout;
    @BindView(R.id.upload_runwater_layout)
    LinearLayout uploadRunwaterLayout;
    @BindView(R.id.brushthe_identity_layout)
    LinearLayout brushtheIdentityLayout;
    @BindView(R.id.ficationing_layout)
    LinearLayout ficationingLayout;
    @BindView(R.id.transaction_detail_recyclerview)
    RecyclerView transactionDetailRecyclerview;
    @BindView(R.id.transaction_detail_layout)
    CardView transactionDetailLayout;
    @BindView(R.id.printing_layout)
    LinearLayout printingLayout;
    @BindView(R.id.transaction_detail_nobtn)
    Button transactionDetailNobtn;
    @BindView(R.id.transaction_detail_yesbtn)
    Button transactionDetailYesbtn;
    @BindView(R.id.transaction_detail_title)
    TextView transactionDetailTitle;
    //    @BindView(R.id.collect_info_recyclerview)
//    RecyclerView collectInfoRecyclerview;

    @BindView(R.id.collect_info_okbtn)
    Button collectInfoOkbtn;
    @BindView(R.id.collect_info_layout)
    LinearLayout collectInfoLayout;
    private int beanlenght;
    private List<StatisticalData_bean> beans;
    private String inquire_type;
    private double zongmoney;
    private int zongnum;
    private double znqkm;
    private int znqkn;
    private double xjhkm;
    private int xjhkn;
    private double zzhkm;
    private int zzhkn;
    private double hzdm;
    private int hzdn;
    private double dzhm;
    private int dzhn;
    private double lwhcm;
    private int lwhcn;
    private String new_password = "";
    private String new_password2 = "";
    private String original_password;
    private double ltjfm;
    private int ltjfn;
    private double ydjfm;
    private int ydjfn;
    private double zhcqym;
    private int zhcqyn;
    private double zhcjm;
    private int zhcjn;
    private double hnyqym;
    private int hnyqyn;
    private double hnyjym;
    private int hnyjyn;
    private double ktgsm;
    private int ktgsn;
    private double zhgmm;
    private int zhgmn;
    private int sgczn;
    private double sgczm;
    private int dy_num = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_operator_service);
        ButterKnife.bind(this);
        this.setBackBtClick(R.id.base_back_btn);
        this.setTitleText(R.id.base_title_text, "(   " + "操作员业务" + "   )");
        handler = new Handler();
        posFuncs = PosFuncs.getInstace();
        posFuncs.init(this);
    }

    @OnClick({R.id.operator_service_uprunwater, R.id.operator_service_changepassword,
            R.id.operator_service_examine_statis, R.id.operator_service_examine_quit,
            R.id.modification_success_okbtn, R.id.statistics_tosee_normal,
            R.id.statistics_tosee_collectl, R.id.statistics_tosee_abnormal,
            R.id.input_querytime_nobtn, R.id.input_querytime_okbtn,
            R.id.sign_out_nobtn, R.id.sign_out_okbtn,
            R.id.transaction_detail_nobtn, R.id.transaction_detail_yesbtn,
            R.id.collect_info_nobtn, R.id.collect_info_okbtn,
            R.id.sure_printingpeper_okbtn,
            R.id.change_password_nobtn,
            R.id.change_password_okbtn,
            R.id.changenew_password_nobtn,

            R.id.changenew_password_okbtn,

            R.id.changenew_password2_nobtn,

            R.id.changenew_password2_okbtn,

    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.operator_service_uprunwater:
                //上传流水
//                Toast.makeText(this, "该功能尚未开通,敬请期待", Toast.LENGTH_SHORT).show();
                operatorServiceHomeLayout.setVisibility(View.GONE);
                dealingLayout.setVisibility(View.VISIBLE);
                String path = "/sdcard/Test/";
                final String strFile = path + "0001" + Constants.YANTAI_TERMNO + DateUtil.getCurrentTime(DateUtil.NOMAL_DATE) + ".txt";
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        mkdirs(strFile);
                    }
                }).start();


                break;
            case R.id.operator_service_changepassword:
                //修改密码
//                Toast.makeText(this, "该功能尚未开通,敬请期待", Toast.LENGTH_SHORT).show();

                operatorServiceHomeLayout.setVisibility(View.GONE);
                changePasswordLayout.setVisibility(View.VISIBLE);

                break;
            case R.id.operator_service_examine_statis:
                //统计查看


                operatorServiceHomeLayout.setVisibility(View.GONE);
                statisticsToseeLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.operator_service_examine_quit:
                //退出操作员
//                Toast.makeText(this, "该功能尚未开通,敬请期待", Toast.LENGTH_SHORT).show();
                Intent intentmain=new Intent(this,LogingActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intentmain);
                this.finish();
//                operatorServiceHomeLayout.setVisibility(View.GONE);
//                signOutLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.modification_success_okbtn:
                //上传流水成功
                operatorServiceHomeLayout.setVisibility(View.VISIBLE);
                modificationSuccessLayout.setVisibility(View.GONE);
                break;
            case R.id.statistics_tosee_normal:
                //正常交易查询
                inquire_type = "zcjy";
                statisticsToseeLayout.setVisibility(View.GONE);
                transactionDetailTitle.setText("本机正常交易明细");
                inputQuerytimeLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.statistics_tosee_collectl:
                //汇总交易查询
                statisticsToseeLayout.setVisibility(View.GONE);
                inputQuerytimeLayout.setVisibility(View.VISIBLE);

                inquire_type = "hzjy";
                break;
            case R.id.statistics_tosee_abnormal:
                //异常交易查询
                inquire_type = "ycjy";
                statisticsToseeLayout.setVisibility(View.GONE);
                transactionDetailTitle.setText("本机异常交易明细");
                inputQuerytimeLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.input_querytime_nobtn:
                //输入时间 更正
                inputQuerytimeEdtext.setText("");
                break;
            case R.id.input_querytime_okbtn:
                //输入时间 确定
                if (inputQuerytimeEdtext.getText().toString().equals("")) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                    //获取当前时间
                    Date date = new Date(System.currentTimeMillis());
                    Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
                    if (inquire_type.equals("hzjy")) {
                        initcollectRecyclerView(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    } else if (inquire_type.equals("zcjy")) {
                        initRecyclerView(simpleDateFormat.format(date).replace("/", ""));
                    } else if (inquire_type.equals("ycjy")) {
                        initundata(simpleDateFormat.format(date).replace("/", ""));
                    }
                } else {
                    if (inquire_type.equals("hzjy")) {
                        initcollectRecyclerView(inputQuerytimeEdtext.getText().toString() + "ALL_DATA");
                    } else if (inquire_type.equals("zcjy")) {
                        initRecyclerView(inputQuerytimeEdtext.getText().toString());
                    } else if (inquire_type.equals("ycjy")) {
                        initundata(inputQuerytimeEdtext.getText().toString());
                    }

//                    String STAT_DATA=  SpUtils.getSPUtil(getApplicationContext()).getString(inputQuerytimeEdtext.getText().toString(),"");
//                   Logger.e(STAT_DATA+"STAT_DATA");
//                    Gson gson = new Gson();
//                    List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
//                    }.getType());

//                    operatorServiceCardLayout.setVisibility(View.GONE);
//                    inputQuerytimeLayout.setVisibility(View.GONE);
//                    transactionDetailLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.sign_out_nobtn:
                //签退 取消
                signOutLayout.setVisibility(View.GONE);
                operatorServiceHomeLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.sign_out_okbtn:
                //签退 确定
                signOutLayout.setVisibility(View.GONE);
                uploadRunwaterLayout.setVisibility(View.VISIBLE);
//                runnable = new Runnable() {
//                    @Override
//                    public void run() {
//                        uploadRunwaterLayout.setVisibility(View.GONE);
//                        operatorServiceHomeLayout.setVisibility(View.VISIBLE);
//                    }
//                };
//                handler.postDelayed(runnable, 1000);
//                Intent i = new Intent("action.exit");
//                sendBroadcast(i);

                break;
            case R.id.transaction_detail_nobtn:
                //打印 取消
                break;
            case R.id.transaction_detail_yesbtn:
                //打印 确定
                surePrintingpeperLayout.setVisibility(View.VISIBLE);
                transactionDetailLayout.setVisibility(View.GONE);
                operatorServiceCardLayout.setVisibility(View.VISIBLE);

//                        operatorServiceHomeLayout.setVisibility(View.VISIBLE);
//                    }
//                };
//                handler.postDelayed(runnable, 1000);
                break;
            case R.id.collect_info_nobtn:
                //本机汇总信息 取消
                this.finish();
                break;
            case R.id.collect_info_okbtn:
                //本机汇总信息 确定 打印
                collectInfoLayout.setVisibility(View.GONE);
                printingLayout.setVisibility(View.VISIBLE);
                if (inputQuerytimeEdtext.getText().toString().equals("")) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                    //获取当前时间
                    Date date = new Date(System.currentTimeMillis());
                    painthz(simpleDateFormat.format(date));
                } else {
                    painthz(inputQuerytimeEdtext.getText().toString());
                }

                break;
            case R.id.sure_printingpeper_okbtn:

                surePrintingpeperLayout.setVisibility(View.GONE);
                operatorServiceCardLayout.setVisibility(View.VISIBLE);
                printingLayout.setVisibility(View.VISIBLE);
//                runnable = new Runnable() {
//                    @Override
//                    public void run() {
                inputQuerytimeEdtext.setText("");
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                final String time = simpleDateFormat.format(date);

                paint(dy_num);


//                printingLayout.setVisibility(View.GONE);
                break;
            case R.id.change_password_nobtn:
                changePasswordEdtext.setText("");
                break;
            case R.id.change_password_okbtn:
                if (changePasswordEdtext.getText().toString().trim().equals("")) {
                    Toast.makeText(this, "请输入您的密码", Toast.LENGTH_SHORT).show();
                } else {
                    original_password = changePasswordEdtext.getText().toString().trim();
                    changePasswordLayout.setVisibility(View.GONE);
                    changenewPasswordLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.changenew_password_nobtn:
                changenewPasswordEdtext.setText("");
                break;
            case R.id.changenew_password_okbtn:
                if (changenewPasswordEdtext.getText().toString().trim().equals("")) {
                    Toast.makeText(this, "请输入您的密码", Toast.LENGTH_SHORT).show();
                } else {
                    new_password = changenewPasswordEdtext.getText().toString().trim();
                    changenewPasswordLayout.setVisibility(View.GONE);
                    changenewPassword2Layout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.changenew_password2_nobtn:
                changenewPassword2Edtext.setText("");
                break;
            case R.id.changenew_password2_okbtn:
                if (changenewPassword2Edtext.getText().toString().trim().equals("")) {
                    Toast.makeText(this, "请输入您的密码", Toast.LENGTH_SHORT).show();
                } else {
                    new_password2 = changenewPassword2Edtext.getText().toString().trim();
                    if (!new_password2.equals(new_password)) {
                        Toast.makeText(this, "两次新密码输入不一致，请重新输入", Toast.LENGTH_SHORT).show();
                        changePasswordLayout.setVisibility(View.VISIBLE);
                        changenewPassword2Layout.setVisibility(View.GONE);
                        changenewPasswordEdtext.setText("");
                        changenewPassword2Edtext.setText("");
                        changePasswordEdtext.setText("");
                    } else {
                        changenewPassword2Layout.setVisibility(View.GONE);
                        dealingLayout.setVisibility(View.VISIBLE);
                        changepass();
                    }

                }
                break;

        }
    }

    /**
     * 创建文件夹
     *
     * @param path
     */
    public void mkdirs(String path) {
        Logger.e(path);
        File f = new File(path);
        String fs = f.getParent();
        f = new File(fs);
        if (!f.exists()) {
            Logger.d("无文件，创建");
            f.mkdirs();

        } else {
            Logger.d("有文件");
//            Logger.e(loadFromSDFile(path));
            if (loadFromSDFile(path) == null) {
                Logger.d("无数据");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        modificationSuccessText.setText("无数据");
                        modificationSuccessLayout.setVisibility(View.VISIBLE);
                    }
                });

            } else {
                //上传流水
                SFTPUtils sftpUtils = new SFTPUtils("172.32.25.234", "user", "user");

                sftpUtils.connect();
                Logger.d("连接成功");
                sftpUtils.uploadFile("/home/user/today/" + DateUtil.getCurrentTime(DateUtil.NOMAL_DATE), "0001" + Constants.YANTAI_TERMNO + DateUtil.getCurrentTime(DateUtil.NOMAL_DATE) + ".txt",
                        Environment.getExternalStorageDirectory().getPath() + "//sdcard/Test/", "0001" + Constants.YANTAI_TERMNO + DateUtil.getCurrentTime(DateUtil.NOMAL_DATE) + ".txt");


                Logger.d("上传成功");
                sftpUtils.disconnect();

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
//                        Toast.makeText(getApplicationContext(), "流水上传成功", Toast.LENGTH_SHORT).show();
                        dealingLayout.setVisibility(View.GONE);
                        modificationSuccessText.setText("交易流水上传完毕");
                        modificationSuccessLayout.setVisibility(View.VISIBLE);
                    }
                });

            }
        }

    }

    private String loadFromSDFile(String fname) {

        Logger.e(fname);
        String result = null;
        try {
            Logger.e(Environment.getExternalStorageDirectory().getPath() + fname);
            File f = new File(Environment.getExternalStorageDirectory().getPath() + fname);
            int length = (int) f.length();
            byte[] buff = new byte[length];
            FileInputStream fin = new FileInputStream(f);
            fin.read(buff);
            fin.close();
            result = new String(buff, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();

        }
        return result;
    }

    private void changepass() {

        Logger.e(new_password+"new_password");
//        String Url = "http://190.190.15.79/api/index/change_user_pwd";//测试
        String Url = "http://172.32.25.235/api/index/change_user_pwd";//正式
//        String Url = "http://huinong.3todo.com/api/index/change_user_pwd";//模拟
        String TermSerial = posFuncs.getTermSerial();
        //获取终端序列号
        Logger.e(SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
        OkHttpUtils
                .post()
                .url(Url)
                .addParam("sn",TermSerial)
                .addParam("old_pwd",original_password)
                .addParam("user_no", SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""))
                .addParam("user_pwd", new_password)

                .build()
                .execute(new Pass_word_Callback() {
                    @Override
                    public Pass_word_bean parseNetworkResponse(Response response, int id) throws Exception {
                        return super.parseNetworkResponse(response, id);

                    }

                    @Override
                    public void onError(Call call, Response response, Exception e, int id) {
                        super.onError(call, response, e, id);
                    }

                    @Override
                    public void onResponse(Pass_word_bean response, int id) {
                        super.onResponse(response, id);
                        if (response.getCode() == 1) {
                            Toast.makeText(OperatorServiceActivity.this, response.getMsg(), Toast.LENGTH_SHORT).show();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    dealingLayout.setVisibility(View.GONE);
                                    modificationSuccessLayout.setVisibility(View.VISIBLE);
                                }
                            });

                        } else {
                            Toast.makeText(OperatorServiceActivity.this, response.getMsg(), Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    }
                });


    }

    private void initundata(String time) {

        String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(time + "UN_DATA", "");
        Logger.e(STAT_DATA + "STAT_DATAUN_DATA");
        if (!STAT_DATA.equals("")) {
            pirntBtn.setVisibility(View.GONE);

            Gson gson = new Gson();
            beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());

            operatorServiceCardLayout.setVisibility(View.GONE);
            inputQuerytimeLayout.setVisibility(View.GONE);
            transactionDetailLayout.setVisibility(View.VISIBLE);
            if (beans.size() != 0) {
                beanlenght = beans.size();
                beans.remove(0);

                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
                transactionDetailRecyclerview.setLayoutManager(linearLayoutManager);
                Transaction_Detail_Adapter adapter = new Transaction_Detail_Adapter(R.layout.transaction_detail_adapter_item_layout, beans);
                transactionDetailRecyclerview.setAdapter(adapter);
            }

        } else {
            pirntBtn.setVisibility(View.GONE);
            Toast.makeText(this, "无记录", Toast.LENGTH_SHORT).show();
        }
    }

    private void paint(final int i) {
        Logger.e(i + "");
        if (beans.size() > 0) {
            String print_data = "";
//        for (int i = 0; i < n; i++) {

            print_data = print_data + " 凭证序号 :" + beans.get(i).getPzh() + " 交易类型 :" + beans.get(i).getType() + " 金额 :" + beans.get(i).getMoney() + " 账号 :" + beans.get(i).getBindnum() + " 户名 :" + beans.get(i).getName();
//            posFuncs.printerAppendTextline(time + " 凭证：" + beans.get(i).getPzh() + " " + beans.get(i).getType());
//            posFuncs.printerAppendTextline("金额 :" + beans.get(i).getMoney());
//            posFuncs.printerAppendTextline("账号 :" + beans.get(i).getBindnum());
//            posFuncs.printerAppendTextline("户名 :" + beans.get(i).getName());
//        }

            final String finalPrint_data = print_data;
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    posFuncs.printerClearBuffer();
                    if (i == 0) {
                        posFuncs.printerAppendLargeTextAlignCenter("正常交易明细 " + beans.get(0).getTime().substring(0, 10));
                    }
                    posFuncs.printerAppendTextline("设备号" + SpUtils.getSPUtil(getApplicationContext()).getString("dev_no", "") +
                            "操作员号" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));

                    posFuncs.printerAppendTextline(finalPrint_data);
                    posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                        @Override
                        public void onSuccess() {
                            if (dy_num == beans.size() - 1) {
                                Toast.makeText(OperatorServiceActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                                finish();
                            } else {
                                dy_num++;
                                paint(dy_num);
                            }

                        }

                        @Override
                        public void onFailed(String error) {
                            if (error.equals("Lack Paper")) {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(OperatorServiceActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                        surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                        printingLayout.setVisibility(View.GONE);
                                    }
                                });
                            }
                        }
                    });
                }
            }.start();
        }
    }

    private void initRecyclerView(String time) {

        String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(time, "");
        Logger.e(STAT_DATA + "STAT_DATA");
        if (!STAT_DATA.equals("")) {


            Gson gson = new Gson();
            beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());

            operatorServiceCardLayout.setVisibility(View.GONE);
            inputQuerytimeLayout.setVisibility(View.GONE);
            transactionDetailLayout.setVisibility(View.VISIBLE);
            if (beans.size() != 0) {
                beanlenght = beans.size();
                beans.remove(0);

                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
                transactionDetailRecyclerview.setLayoutManager(linearLayoutManager);
                Transaction_Detail_Adapter adapter = new Transaction_Detail_Adapter(R.layout.transaction_detail_adapter_item_layout, beans);
                transactionDetailRecyclerview.setAdapter(adapter);
            }

        } else {
            Toast.makeText(this, "无记录", Toast.LENGTH_SHORT).show();
        }
    }

    private void initcollectRecyclerView(String key) {
        inputQuerytimeLayout.setVisibility(View.GONE);
        collectInfoLayout.setVisibility(View.VISIBLE);
        DecimalFormat df = new DecimalFormat("#.00");


        String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(key, "");
        Logger.e(STAT_DATA + "ALL_DATA");
        if (!STAT_DATA.equals("")) {
            Gson gson = new Gson();
            List<Summary_Bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<Summary_Bean>>() {
            }.getType());
            String znqu[] = beans.get(0).getZnqk().split(",");
            if (znqu.length != 1) {
                if (znqu[0].contains(".")) {
                    String moneys[] = znqu[0].split("\\.");
                    String money_start = moneys[0];
                    String money_end = moneys[1];
                    if (money_end.length() == 1) {
                        double m = Double.parseDouble(money_start + "." + money_end + "0");
                        if (money_start.equals("0")) {
                            znqkMoney.setText("0" + df.format(m) + "");
                        } else {
                            znqkMoney.setText(df.format(m) + "");
                        }

                    } else {
                        double m = Double.parseDouble(money_start + "." + money_end);
                        if (money_start.equals("0")) {
                            znqkMoney.setText("0" + df.format(m) + "");
                        } else {
                            znqkMoney.setText(df.format(m) + "");
                        }
                    }

                } else {
                    znqkMoney.setText(znqu[0]);
                }

                znqkNum.setText(znqu[1]);
                znqkm = Double.parseDouble(znqu[0]);
                znqkn = Integer.parseInt(znqu[1]);
            }

            String xjhk[] = beans.get(0).getXjhk().split(",");
            Logger.e(xjhk.length + "......");
            if (xjhk.length != 1) {

                if (xjhk[0].contains(".")) {

                    String moneys[] = xjhk[0].split("\\.");
                    String money_start = moneys[0];
                    String money_end = moneys[1];
                    Logger.e(money_start + "money_start" + money_end);

                    if (money_end.length() == 1) {

//                        xjhkMoney.setText(money_start + "." + money_end+"0");
                        double m = Double.parseDouble(money_start + "." + money_end + "0");
                        if (money_start.equals("0")) {
                            xjhkMoney.setText("0" + df.format(m) + "");
                        } else {
                            xjhkMoney.setText(df.format(m) + "");
                        }
                    } else {

                        double m = Double.parseDouble(money_start + "." + money_end);
                        if (money_start.equals("0")) {
                            xjhkMoney.setText("0" + df.format(m) + "");
                        } else {
                            xjhkMoney.setText(df.format(m) + "");
                        }

                    }
                } else {
                    Logger.e("aaaa");
                    xjhkMoney.setText(xjhk[0]);
                }
                xjhkNum.setText(xjhk[1]);
                xjhkm = Double.parseDouble(xjhk[0]);
                xjhkn = Integer.parseInt(xjhk[1]);
            }


            String zzhk[] = beans.get(0).getZzhk().split(",");
            Logger.e(zzhk.length + "......");
            if (zzhk.length != 1) {
                if (zzhk[0].contains(".")) {
                    String moneys[] = zzhk[0].split("\\.");
                    String money_start = moneys[0];
                    String money_end = moneys[1];
                    if (money_end.length() == 1) {
                        double m = Double.parseDouble(money_start + "." + money_end + "0");
                        if (money_start.equals("0")) {
                            zzhkMoney.setText("0" + df.format(m) + "");
                        } else {
                            zzhkMoney.setText(df.format(m) + "");
                        }

                    } else {
                        double m = Double.parseDouble(money_start + "." + money_end);
                        if (money_start.equals("0")) {
                            zzhkMoney.setText("0" + df.format(m) + "");
                        } else {
                            zzhkMoney.setText(df.format(m) + "");
                        }
                    }
                } else {
                    zzhkMoney.setText(zzhk[0]);
                }
                zzhkNum.setText(zzhk[1]);
                zzhkm = Double.parseDouble(zzhk[0]);
                zzhkn = Integer.parseInt(zzhk[1]);
            }


            String hzd[] = beans.get(0).getHzd().split(",");
            Logger.e(hzd.length + "hzd");
            if (hzd.length != 1) {
                if (hzd[0].contains(".")) {
                    hzdMoney.setText(hzd[0].split("\\.")[0] + ".00");

                    hzdNum.setText(hzd[1]);
                    hzdm = Double.parseDouble(hzd[0].split("\\.")[0] + ".00");
                    hzdn = Integer.parseInt(hzd[1]);
                } else {
                    hzdMoney.setText(hzd[0] + "." + "00");

                    hzdNum.setText(hzd[1]);
                    hzdm = Double.parseDouble(hzd[0]);
                    hzdn = Integer.parseInt(hzd[1]);
                }


            }
            String dzh[] = beans.get(0).getDzh().split(",");
            Logger.e(dzh.length + "......");
            if (dzh.length != 1) {
                if (dzh[0].contains(".")) {
                    dzhMoney.setText(dzh[0].split("\\.")[0] + ".00");
                    dzhNum.setText(dzh[1]);
                    dzhm = Double.parseDouble(dzh[0].split("\\.")[0]);
                    dzhn = Integer.parseInt(dzh[1]);
                } else {
                    dzhMoney.setText(dzh[0] + "." + "00");
                    dzhNum.setText(dzh[1]);
                    dzhm = Double.parseDouble(dzh[0]);
                    dzhn = Integer.parseInt(dzh[1]);
                }

            }

            String Lwhc[] = beans.get(0).getLwhc().split(",");
            Logger.e(Lwhc.length + Lwhc[0]);
            if (Lwhc.length != 1) {
                lwhcMoney.setText("/");
                lwhcNum.setText(Lwhc[1]);
                lwhcm = Double.parseDouble(Lwhc[0]);
                lwhcn = Integer.parseInt(Lwhc[1]);
            }
//联通缴费
            String ltjf[] = beans.get(0).getLthf().split(",");

            if (ltjf.length != 1) {

                if (ltjf[0].contains(".")) {

                    String moneys[] = ltjf[0].split("\\.");
                    String money_start = moneys[0];
                    String money_end = moneys[1];
                    Logger.e(money_start + "money_start" + money_end);

                    if (money_end.length() == 1) {

//                        xjhkMoney.setText(money_start + "." + money_end+"0");
                        double m = Double.parseDouble(money_start + "." + money_end + "0");
                        if (money_start.equals("0")) {
                            lthfMoney.setText("0" + df.format(m) + "");
                        } else {
                            lthfMoney.setText(df.format(m) + "");
                        }
                    } else {

                        double m = Double.parseDouble(money_start + "." + money_end);
                        if (money_start.equals("0")) {
                            lthfMoney.setText("0" + df.format(m) + "");
                        } else {
                            lthfMoney.setText(df.format(m) + "");
                        }

                    }
                } else {
                    Logger.e("aaaa");
                    lthfMoney.setText(ltjf[0]);
                }
                lthfNum.setText(ltjf[1]);
                ltjfm = Double.parseDouble(ltjf[0]);
                ltjfn = Integer.parseInt(ltjf[1]);
            }

            //移动缴费
            String ydjf[] = beans.get(0).getYdhf().split(",");

            if (ydjf.length != 1) {

                if (ydjf[0].contains(".")) {

                    String moneys[] = ydjf[0].split("\\.");
                    String money_start = moneys[0];
                    String money_end = moneys[1];
                    Logger.e(money_start + "money_start" + money_end);

                    if (money_end.length() == 1) {

//                        xjhkMoney.setText(money_start + "." + money_end+"0");
                        double m = Double.parseDouble(money_start + "." + money_end + "0");
                        if (money_start.equals("0")) {
                            ydhfMoney.setText("0" + df.format(m) + "");
                        } else {
                            ydhfMoney.setText(df.format(m) + "");
                        }
                    } else {

                        double m = Double.parseDouble(money_start + "." + money_end);
                        if (money_start.equals("0")) {
                            ydhfMoney.setText("0" + df.format(m) + "");
                        } else {
                            ydhfMoney.setText(df.format(m) + "");
                        }

                    }
                } else {
                    Logger.e("aaaa");
                    ydhfMoney.setText(ydjf[0]);
                }
                ydhfNum.setText(ydjf[1]);
                ydjfm = Double.parseDouble(ydjf[0]);
                ydjfn = Integer.parseInt(ydjf[1]);
            }

            //智慧存签约
            String Zhcqy[] = beans.get(0).getZhcqy().split(",");

            if (Zhcqy.length != 1) {


                zhcqyMoney.setText(Zhcqy[0]);

                zhcqyNum.setText(Zhcqy[1]);
                zhcqym = Double.parseDouble(Zhcqy[0]);
                zhcqyn = Integer.parseInt(Zhcqy[1]);
            }
            //智慧存解约
            String Zhcjy[] = beans.get(0).getZhcjy().split(",");

            if (Zhcjy.length != 1) {


                zhcjyMoney.setText(Zhcjy[0]);

                zhcjyNum.setText(Zhcjy[1]);
                zhcjm = Double.parseDouble(Zhcjy[0]);
                zhcjn = Integer.parseInt(Zhcjy[1]);
            }
            //惠农赢签约
            String hnyqy[] = beans.get(0).getHnyqy().split(",");

            if (hnyqy.length != 1) {
                if (hnyqy[0].contains(".")) {
                    hnyqyMoney.setText(hnyqy[0].split("\\.")[0] + ".00");

                    hnyqyNum.setText(hnyqy[1]);
                    hnyqym = Double.parseDouble(hnyqy[0].split("\\.")[0]);
                    hnyqyn = Integer.parseInt(hnyqy[1]);
                } else {
                    hnyqyMoney.setText(hnyqy[0]);

                    hnyqyNum.setText(hnyqy[1]);
                    hnyqym = Double.parseDouble(hnyqy[0]);
                    hnyqyn = Integer.parseInt(hnyqy[1]);
                }

            }
            //惠农赢j约
            String hnyjy[] = beans.get(0).getHnyjy().split(",");

            if (hnyjy.length != 1) {
                if (hnyjy[0].contains(".")) {
                    hnyjyMoney.setText(hnyjy[0].split("\\.")[0] + ".00");

                    hnyjyNum.setText(hnyjy[1]);
                    hnyjym = Integer.parseInt(hnyjy[0].split("\\.")[0]);
                    hnyjyn = Integer.parseInt(hnyjy[1]);
                } else {
                    hnyjyMoney.setText(hnyjy[0]);

                    hnyjyNum.setText(hnyjy[1]);
                    hnyjym = Integer.parseInt(hnyjy[0]);
                    hnyjyn = Integer.parseInt(hnyjy[1]);
                }

            }
            //口头挂失
            String ktgs[] = beans.get(0).getKtgs().split(",");

            if (ktgs.length != 1) {
                ktgsMoney.setText(ktgs[0] + "." + "00");

                ktgsNum.setText(ktgs[1]);
                ktgsm = Double.parseDouble(ktgs[0]);
                ktgsn = Integer.parseInt(ktgs[1]);
            }
            //账号改密
            String zhgm[] = beans.get(0).getZhgm().split(",");

            if (zhgm.length != 1) {
                zhgmMoney.setText(zhgm[0] + "." + "00");

                zhgmNum.setText(zhgm[1]);
                zhgmm = Double.parseDouble(zhgm[0]);
                zhgmn = Integer.parseInt(zhgm[1]);
            }
            //手工冲正
            String zsgc[] = beans.get(0).getSgcc().split(",");

            if (zsgc.length != 1) {
                sgczMoney.setText(zsgc[0] + "." + "00");

                sgczNum.setText(zsgc[1]);
                sgczm = Double.parseDouble(zsgc[0]);
                sgczn = Integer.parseInt(zsgc[1]);
            }
        }


//            Logger.e(zzhk[0]);
//            Logger.e(hzd[0]);
//            Logger.e(dzh[0]);
//            zongmoney = znqkm + xjhkm + zzhkm + hzdm + dzhm;
//            zongnum = znqkn + xjhkn + zzhkn + hzdn + dzhn;
        zongmoney = znqkm + xjhkm + zzhkm + hzdm + dzhm + hnyqym + hnyjym + zhcqym + zhcjm + ltjfm + ydjfm;
        zongnum = znqkn + xjhkn + zzhkn + hzdn + dzhn + hnyqyn + hnyjyn + zhcqyn + zhcjn + ltjfn + ydjfn + lwhcn + ktgsn + zhgmn + sgczn;
        Logger.e(zongmoney + "");
        if (df.format(zongmoney).equals(".00")) {
            allMoney.setText("0.00");
        } else if (zongmoney < 1) {
            String m = String.valueOf(zongmoney);
            if (m.length() > 4) {
                allMoney.setText(m.substring(0, 3));
            } else {
                allMoney.setText(zongmoney + "");
            }

        } else {
            allMoney.setText("" + df.format(zongmoney));
        }

        allNum.setText(String.valueOf(zongnum));


    }

    private void painthz(final String timess) {

        handler.postDelayed(runnable, 1000);
        new Thread() {
            @Override
            public void run() {
                super.run();
                DecimalFormat df = new DecimalFormat("#.00");
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("汇总统计" + timess);

                posFuncs.printerAppendTextline("                   " + "金额" + "  " + "笔数");

                posFuncs.printerAppendTextline("助农取款    :" + znqkMoney.getText().toString() + "   |   " + znqkNum.getText().toString());
                posFuncs.printerAppendTextline("现金汇款    :" + xjhkMoney.getText().toString() + "   |   " + xjhkNum.getText().toString());
                posFuncs.printerAppendTextline("转账汇款    :" + zzhkMoney.getText().toString() + "   |   " + zzhkNum.getText().toString());
                posFuncs.printerAppendTextline("移动话费    :" + ydhfMoney.getText().toString() + "   |   " + ydhfNum.getText().toString());
                posFuncs.printerAppendTextline("联通话费    :" + lthfMoney.getText().toString() + "   |   " + lthfNum.getText().toString());
                posFuncs.printerAppendTextline("手工冲正    :" + sgczMoney.getText().toString() + "   |   " + sgczNum.getText().toString());
                posFuncs.printerAppendTextline("定期转活期  :" + dzhMoney.getText().toString() + "   |   " + dzhNum.getText().toString());
                posFuncs.printerAppendTextline("活期转定期  :" + hzdMoney.getText().toString() + "   |   " + hzdNum.getText().toString());
                posFuncs.printerAppendTextline("账号改密    :" + zhgmMoney.getText().toString() + "   |   " + zhgmNum.getText().toString());
                posFuncs.printerAppendTextline("联网核查    :" + lwhcMoney.getText().toString() + "   |   " + lwhcNum.getText().toString());
                posFuncs.printerAppendTextline("口头挂失    :" + ktgsMoney.getText().toString() + "   |   " + ktgsNum.getText().toString());
                posFuncs.printerAppendTextline("智慧存签约  :" + zhcqyMoney.getText().toString() + "   |   " + zhcqyNum.getText().toString());
                posFuncs.printerAppendTextline("智慧存解约  :" + zhcjyMoney.getText().toString() + "   |   " + zhcjyNum.getText().toString());
                posFuncs.printerAppendTextline("惠农赢签约  :" + hnyqyMoney.getText().toString() + "   |   " + hnyqyNum.getText().toString());
                posFuncs.printerAppendTextline("惠农赢解约  :" + hnyjyMoney.getText().toString() + "   |   " + hnyjyNum.getText().toString());
                if (df.format(zongmoney).equals(".00")) {
                    posFuncs.printerAppendTextline("汇总        " + "0.00" + "      " + zongnum);
                } else if (zongmoney < 1) {
                    posFuncs.printerAppendTextline("汇总        " + zongmoney + "      " + zongnum);
                } else {
                    posFuncs.printerAppendTextline("汇总        " + df.format(zongmoney) + "      " + zongnum);

                }
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(OperatorServiceActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(OperatorServiceActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }


}
